'''
Created on 2009-11-30

@author: Jialai_Zhu
'''
# parsexml.py  
 
import xml.parsers.expat  
from   maltree import mufs  

level = 0  

t = '''
<br>
<span>
%s(%d)[%s]
<a href="%s" class="smarterwiki-linkify">
%s
</a>
</span>
<br>
'''  
  
def start_element(name, attrs):  
    global level  
#    print '  '*level, 'Start element:', name, attrs  
    try:
        print t % ('&nbsp;' * level * 2, level, attrs['type'], 'mufs//' + attrs['md5u'], attrs['url'])
    except:
        pass
    level = level + 1  
  
  
def end_element(name):  
    global level  
    level = level - 1  
#    print '  '*level, 'End element:', name  
      
  
def char_data(data):  
    if(data == '\n'):  
        return  
    if(data.isspace()):  
        return  
    global level  
#    print '  '*level, 'Character data:', data  
  
p = xml.parsers.expat.ParserCreate()  
  
p.StartElementHandler = start_element  
p.EndElementHandler = end_element  
p.CharacterDataHandler = char_data  
p.returns_unicode = False  


dir = r'd:\\threat solution\\eclipse\\workspace\\ciss\\src\\maltree\\mufs\\41faaac21faaf619653d0314cd0cb55e.xml'
def run(path):
    print "<html>"
    f = file(path)  
    p.ParseFile(f)  
    f.close() 
    print "</html>"

